#include <bits/stdc++.h>

using namespace std;
#define int long long
const int inf = 0x3f3f3f3f;

void solve()
{
	int n, s;
	cin >> n >> s;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	int left = 0, right = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] < s && s - a[i] > left) left = s - a[i];
		else if (a[i] > s && a[i] - s > right) right = a[i] - s;
	}
	cout << min(left + left + right, left + 2 * right) << endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	cin >> _;
	while (_--)
	{
		solve();
	}
	return 0;
}